﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    <link rel="stylesheet" href="~/Content/bootstrap.min.css" />
    <link rel="stylesheet" href="~/Content/bootstrap-table.css" />
    <link rel="stylesheet" href="~/Content/style.css" />
    <style>
        .fixed-table-container {
            border: none;
        }
        p{
            margin:0 !important;
        }
        tr td:last-child{
            text-align:left !important;
        }
    </style>
</head>
<body>

    @Html.Action("Top", "Home")
    <div class="table1" style="margin-top:20px;">
        <p>数据库备份列表</p>
        <table style="border:1px solid #dddddd"></table>
    </div>
    <form class="form2" onsubmit="return onSubmitBackup();">
        <h2 style="margin-top:0;margin-bottom:0;">数据库备份</h2>
        <p><span>当前数据库版本：</span>MySQL5.0</p>
        <p><span>选择备份数据格式：</span><input name="banben" type="radio" value="" />MySQL3.x/4.0.x 版本　<input name="banben" type="radio" value="" />MySQL4.1.x/5.x 版本   </p>
        <p><span>输入数据库备份名：</span><input type="text" name="bkname">  <input type="submit" value="提交备份" /></p>
    </form>

    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script src="~/Scripts/bootstrap-table.js"></script>
    <script src="~/Scripts/locale/bootstrap-table-zh-CN.js"></script>
    <script src="~/Scripts/menu.js"></script>
    <script src="~/Scripts/uilts.js"></script>
    <script>
        var $table = $('table');
        function InitTable(pageIndex, pageSize) {
            if (typeof pageIndex == "object") {
                pageIndex = undefined;
            }
            $table.bootstrapTable('destroy');
            $table.bootstrapTable({
                method: "post",  //使用get请求到服务器获取数据
                url: "/System/recordlist", //获取数据的Servlet地址
                striped: true,  //表格显示条纹
                pagination: true, //启动分页
                pageSize: pageSize == null ? 10 : pageSize,  //每页显示的记录数
                pageNumber: pageIndex == null ? 1 : pageIndex, //当前第几页
                pageList: [10, 20, 50, 100, 250],  //记录数可选列表
                search: false,  //是否启用查询
                sidePagination: "server", //表示服务端请求
                sortName: "ID",
                //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                //设置为limit可以获取limit, offset, search, sort, order
                queryParamsType: "undefined",
                queryParams: function queryParams(params) {   //设置查询参数
                    var param = {
                        PageIndex: params.pageNumber,
                        PageSize: params.pageSize,
                        sorter: params.sortName + " " + params.sortOrder
                    };
                    return param;
                },
                columns: [
                    {
                        field: 'Name',
                        title: "备份名称",
                        align: 'center',
                        valign: 'middle'
                    },
                    {
                        field: 'Time',
                        title: '备份时间',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            if (value == null || value == "/Date(-62135596800000)/")
                                return null
                            var date = new Date(parseInt(value.substr(6)));
                            return date.toLocaleDateString(["zh-CN"]);

                        }
                    },
                    {
                        field: '',
                        title: '操作',
                        align: 'center',
                        valign: 'middle',
                        formatter: function (value, row, index) {
                            return '<a href="javascript:;" data-id="' + row["ID"] + '" onclick="onDeleteItem(this);">删除</a><a href="javascript:;" data-id="' + row["ID"] + '" onclick="onRestoreItem(this);">还原</a>';
                        }
                    }
                ],
                onLoadSuccess: function () {
                    $('table tr:even').find('td').css("background", "#e9f3ff");
                    $('table tr').click(function () {
                        uncheckAll($table);
                        $('table tr').removeClass("act");
                        $(this).addClass("act");
                        $table.bootstrapTable('check', $(this).attr("data-index"));
                    });
                }
            });
        }

        InitTable();

    </script>
    <script>
        function onSubmitBackup() {
            var bname = $("input[name='bkname']").val().trim();
            if (bname == "" || bname.length > 50) {
                alert("备份名不能为空且长度不能超过50个字符！");
                return false;
            }
            PostApi('/System/AddBackup', $("form.form2").serialize(), function (result) {
                if (result.code == 0) {
                    InitTable();
                    alert("备份成功！");
                } else {
                    alert(result.ErrorMessage);
                }
            }, function () {
                alert("备份失败！");
            });
            return false;
        }

        function onRestoreItem(obj) {
            var id = $(obj).attr("data-id");
            if (id != undefined) {
                PostApi("/System/RestoreBackup", { id: id }, function (result) {
                    if (result.code == 0) {
                        InitTable();
                        alert("删除成功！");
                    } else {
                        alert(result.ErrorMessage);
                    }
                }, function () {
                    alert("删除失败！");
                });
            }
        }

        function onDeleteItem(obj) {
            var id = $(obj).attr("data-id");
            if (id != undefined) {
                PostApi("/System/DeleteBackup", { id: id }, function (result) {
                    if (result.code == 0) {
                        InitTable();
                        alert("删除成功！");
                    } else {
                        alert(result.ErrorMessage);
                    }
                }, function () {
                    alert("删除失败！");
                });
            }
        }
    </script>
</body>
</html>
